package br.com.serctam.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.ManyToOne;
import javax.persistence.Version;

import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;


/**
 * Esta classe tem o objetivo de guardar o ultimo numero de inscrisao utilizado
 * @author celio
 *
 */

@NamedQueries({
	@NamedQuery(name="buscaUltimoNumeroInscrisao" , query=" select max(ni.ultimoNumero)  from NumeroInscrisao ni where ni.cargo.id = :idCargo "),
	@NamedQuery(name="atualizaUltimoNumeroInscrisao" , query=" update NumeroInscrisao ni set ni.ultimoNumero = :ultimo where ni.cargo.id = :idCargo ")
})

@Entity
public class NumeroInscrisao implements Serializable
{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3980181673361735510L;
	// seam-gen attributes (you should probably edit these)
    private Long id;
    private Integer version;
    private Integer ultimoNumero;
    private Cargo cargo;
    


	@Id @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Version
    public Integer getVersion() {
        return version;
    }

    private void setVersion(Integer version) {
        this.version = version;
    }


    @NotNull
    public Integer getUltimoNumero() {
		return ultimoNumero;
	}

	public void setUltimoNumero(Integer ultimoNumero) {
		this.ultimoNumero = ultimoNumero;
	}

    
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NumeroInscrisao other = (NumeroInscrisao) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@ManyToOne
	public Cargo getCargo() {
		return cargo;
	}

	public void setCargo(Cargo cargo) {
		this.cargo = cargo;
	}
	
	

}
